/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AltaNumeroSensoresGrupo.java
 *
 * Created on 17/11/2011, 02:21:21 AM
 */
package vista.panel.altas;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import logica.GrupoSensores;
import modelo.Grupo;
import modelo.SustratoNave;

/**
 *
 * @author Elias Mendoza
 */
public class AltaNumeroSensoresGrupo extends javax.swing.JPanel {
  SustratoNave sn;
  int [] grupo;
  DefaultListModel modeloGrupos = new DefaultListModel();
  DefaultListModel modeloGruposSensores = new DefaultListModel();
  /** Creates new form AltaNumeroSensoresGrupo */
  public AltaNumeroSensoresGrupo(SustratoNave sn,int [] grupo) {
    initComponents();
    this.sn = sn;
    this.grupo = grupo;
    grupos.setModel(modeloGrupos);
    grupoSensores.setModel(modeloGruposSensores);
    
    Burbuja(grupo,grupo.length-1);
    imprimir(grupo);
  }

  void Burbuja(int x[], int n) {
    int b, j, t;
    do {
      b = 0;
      for (j = 0; j < n; j++) {
        if (x[j] > x[j + 1]) {
          t = x[j];
          x[j] = x[j + 1];
          x[j + 1] = t;
          b++;
        }
      }
      n--;
    } while (b > 0);
  }
  public void imprimir(int [] grupo){
    for(int i =0;i<grupo.length;i++){
      char c = (char) grupo[i];
      System.out.println(c);
      modeloGrupos.addElement(c);
    }
  }


  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        grupos = new javax.swing.JList();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        numeroSensores = new javax.swing.JSpinner();
        asigna = new javax.swing.JButton();
        registrar = new javax.swing.JButton();
        cancelar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        grupoSensores = new javax.swing.JList();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Numero de Sensores que Tendra el Grupo", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        setLayout(new java.awt.GridBagLayout());

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        grupos.setBorder(javax.swing.BorderFactory.createTitledBorder("Grupos"));
        grupos.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        grupos.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
        jScrollPane1.setViewportView(grupos);

        jPanel2.add(jScrollPane1);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 12));
        jLabel1.setForeground(new java.awt.Color(0, 153, 51));
        jLabel1.setText("Numero de Sensores (<=16)");

        asigna.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vista/img/asigna.png"))); // NOI18N
        asigna.setBorder(null);
        asigna.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                asignaActionPerformed(evt);
            }
        });

        registrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vista/img/registrar.png"))); // NOI18N
        registrar.setBorder(null);

        cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vista/img/cancelar.png"))); // NOI18N
        cancelar.setBorder(null);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel1))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(numeroSensores, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(asigna))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(registrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelar)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addGap(11, 11, 11)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(numeroSensores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(asigna))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 60, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(registrar)
                    .addComponent(cancelar)))
        );

        grupoSensores.setBorder(javax.swing.BorderFactory.createTitledBorder("Grupo y Sensores"));
        grupoSensores.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        jScrollPane2.setViewportView(grupoSensores);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        add(jPanel1, new java.awt.GridBagConstraints());
    }// </editor-fold>//GEN-END:initComponents

  private void asignaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_asignaActionPerformed
    // TODO add your handling code here:
    
  }//GEN-LAST:event_asignaActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton asigna;
    private javax.swing.JButton cancelar;
    private javax.swing.JList grupoSensores;
    private javax.swing.JList grupos;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSpinner numeroSensores;
    private javax.swing.JButton registrar;
    // End of variables declaration//GEN-END:variables
}
